/*
 * @Author: sunzhijun 
 * @Date: 2019-10-30 15:23:17 
 * @Last Modified by: sunzhijun
 * @Last Modified time: 2020-03-31 16:55:21
 */

import React from 'react';
import './index.less';
import {createPage, high} from 'nc-lightapp-front';
import {render} from 'src/hrpub/common/frame';
import Layout from 'src/hrpub/common/components/Layout';

import EmptyData from 'src/hrpub/common/components/emptyImg';
import HeaderContent from '../components/HeaderContent';
import TableList from '../components/TableList';
import CardForm from '../components/CardForm';
import NewAdd from '../components/NewAdd';
import CardPagination from '../components/CardPagination';

import MainAction from '../actions/main';
import HeaderAction from '../actions/header';
import BtnAction from '../actions/btn';
import TableAction from '../actions/table';
import CardAction from '../actions/card';
import { getAppPageConfig } from 'src/hrpub/common/utils/utils';
import ViewCard from 'src/hrpub/common/components/card-view';
import ApproveDetail from 'uap/common/components/ApproveDetail';
import ApprovalTrans from 'uap/common/components/approvalTrans';
import WpsModal from 'src/hrpub/common/components/wpsPreModel';
import FileUpload from '../../../public/components/FileUpload';
const {Header, Left, Content} = Layout;
const HomePage = render({
    actions: {
        mainAct: MainAction,
        btnAct: BtnAction,
        headerAct: HeaderAction,
        tableAct: TableAction,
        cardAct: CardAction
    }
})(({props, action, state}) => {
    const { main } = props;
    let { isShowOrg, orgValue, pk_org, isCardForm, showFlowModal, billtype, billid, fromApprove, language, nodeRefs, designateDisplay, designateData } = main;
    console.log(nodeRefs)
    return (
        <Layout className="main-page">
            <Header 
                showOrgRefer={ isShowOrg }
                {...props} 
                orgReferOptions={{
                    getOrgData: action.headerAct.changeOrg,
                    orgVal: orgValue,
                    // disabled: true
                }}
                buttonOptions={{
                    area: 'head',
                    onButtonClick: action.btnAct.headerClick
                }}
                customButton = {fromApprove ? null :<CardPagination {...props} action = {action}></CardPagination>}
            >
                { fromApprove ? null : <HeaderContent
                    {...props}
                    action = { action }
                ></HeaderContent> }
            </Header>
            <div className="container nc-bill-card">
                <If condition={!!pk_org}>
                    <If condition={fromApprove? isCardForm : !isCardForm}>
                        <TableList
                            {...props}
                            action = { action }
                        >
                        </TableList>
                    </If>
                    <If condition={fromApprove ? !isCardForm : isCardForm}>
                        <CardForm
                            {...props}
                            action = { action }
                        ></CardForm>
                    </If>
                </If>
                <If condition={!pk_org}>
                    <EmptyData text={language['hrcm-000017']}></EmptyData>
                </If>
                {/* 新增 */}
                <NewAdd
                    {...props}
                    action = { action }
                ></NewAdd>
                {/* 流程历史 */}
                <ApproveDetail
                    show={showFlowModal}
                    close={action.headerAct.closeApproveDetailModal}
                    billtype={billtype}  //billMessage.billtype
                    billid={billid}  //billMessage.billid
                />
                {/* 联查卡片 */}
                <ViewCard
                    { ...props }
                    onRef ={ 
                        node => nodeRefs.showCardViewRefs = node
                    }
                ></ViewCard>
                <WpsModal
                        {...props}
                        onRef ={node => nodeRefs.wpsview = node}
                        appcode={getAppPageConfig().appcode}
                        pk_org={pk_org}
                    
                    />
                {/* 指派 */}
                { designateDisplay ? <ApprovalTrans
                    // title={json['hrcm-000069']}/* 国际化处理： 指派*/
                    data={designateData}
                    display={designateDisplay}
                    getResult={action.headerAct.submitDesignate}
                    cancel={action.headerAct.hideDesignate}
                /> : null}
                <FileUpload json={language} {...props} ref={(node) => nodeRefs.fileUpload = node}/>
            </div>
        </Layout>
    );
});

export default createPage({
    // billinfo: {
    //     billtype: 'extcard', 
    //     pagecode: getAppPageConfig().appcode, 
    //     headcode: 'form',
    //     bodycode: ['dataBefore', 'dataAfter']
    // }
})(HomePage);